//
//  PingJiangTableViewCell.swift
//  RoundCatPlay2
//
//  Created by 姜澎 on 2019/10/30.
//  Copyright © 2019 jiangpeng. All rights reserved.
//

import UIKit

class PingJiaTableViewCell: UITableViewCell {
    
    var pingJiaModel: PingJiaModel? {
        didSet {
            self.titleImage.image = UIImage(named: pingJiaModel!.image)
            self.titleName.text = pingJiaModel?.title
            self.contentL.text = pingJiaModel?.content
            self.dateLable.text = pingJiaModel?.date
            self.zanNum.text = "\(pingJiaModel?.imageNum ?? 0)" + "分"
        }
    }
    
    public var count:Int = 0
    
    public  var priuter: [UIView] = [UIView]()
    
    
    private lazy var titleImage: UIImageView = {
        let i = UIImageView()
        return i
    }()
    
    private lazy var titleName: UILabel = {
        let l = UILabel()
        l.font = UIFont.systemFont(ofSize: 14)
        l.textColor = UIColor(red: 151.0 / 255.0, green: 151.0 / 255.0, blue: 151.0 / 255.0, alpha: 1.0)
        return l
    }()
    
    private lazy var contentL: UILabel = {
        let l = UILabel()
        l.numberOfLines = 0
        l.font = UIFont.systemFont(ofSize: 16)
        return l
    }()
    
    private lazy var dateLable: UILabel = {
        let l = UILabel()
        l.textColor = UIColor(red: 151.0 / 255.0, green: 151.0 / 255.0, blue: 151.0 / 255.0, alpha: 1.0)
        l.font = UIFont.systemFont(ofSize: 12)
        return l
    }()
    
    private lazy var bottomLine: UIView = {
        let v = UIView()
        v.backgroundColor = UIColor(red: 234/255, green: 234/255, blue: 234/255, alpha: 1)
        return v
    }()
    
    private lazy var zanView: UIView = {
        let v = UIView()
        for i in 0..<5{
            var zanImage: UIImageView = UIImageView()
            zanImage.image = UIImage(named: "xing")
            zanImage.frame = CGRect(x: i * 25, y: 0, width: 20, height: 17)
            v.addSubview(zanImage)
        }
        self.priuter = v.subviews
        
        return v
    }()
    
    private lazy var zanNum: UILabel = {
        let i = UILabel()
        i.font = UIFont.systemFont(ofSize: 15)
        i.textColor = UIColor(red: 243.0 / 255.0, green: 123.0 / 255.0, blue: 123.0 / 255.0, alpha: 1.0)
        return i
    }()

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
    }

}

extension PingJiaTableViewCell {
    func setUI() {
        addSubview(self.titleImage)
        addSubview(self.titleName)
        addSubview(self.contentL)
        addSubview(self.dateLable)
        addSubview(self.zanView)
        addSubview(self.zanNum)
        addSubview(self.bottomLine)
        
        setTitleImageFrame()
        setTitleNameFrame()
        setContentLFrame()
        setDateLableFrame()
        setZanViewFrame(count: self.count)
        setZanNumFrame()
        setBottomLine()
    }
    
    func setTitleImageFrame() {
        self.titleImage.snp.makeConstraints { (make) in
            make.top.equalTo(10)
            make.left.equalTo(23)
            make.height.equalTo(35)
            make.width.equalTo(36)
        }
    }
    
    func setTitleNameFrame() {
        self.titleName.snp.makeConstraints { (make) in
            make.top.equalTo(self.titleImage.snp_top)
            make.left.equalTo(self.titleImage.snp_right).offset(10)
            
        }
    }
    
    func setContentLFrame() {
        self.contentL.snp.makeConstraints { (make) in
            make.left.equalTo(self.titleName.snp_left)
            make.right.equalTo(-18)
            make.top.equalTo(self.titleName.snp_bottom).offset(10)
            make.bottom.equalTo(self.zanView.snp_top).offset(-10)
        }
    }
    
    func setDateLableFrame() {
        self.dateLable.snp.makeConstraints { (make) in
            make.top.equalTo(self.titleName.snp_top)
            make.right.equalTo(-18)
        }
    }
    
    func setZanViewFrame(count :Int) {
        self.zanView.snp.makeConstraints { (make) in
            make.left.equalTo(titleName.snp_left)
            make.bottom.equalTo(-30)
        }
    }
    
    func setZanNumFrame() {
        self.zanNum.snp.makeConstraints { (make) in
            make.top.equalTo(self.zanView.snp_top)
            make.left.equalTo(self.zanView.snp_right).offset(125)

        }
    }
    func setBottomLine() {
        self.bottomLine.snp.makeConstraints { (make) in
            make.left.equalTo(23)
            make.right.equalTo(-18)
            make.bottom.equalTo(0)
            make.height.equalTo(1)
        }
    }
}
